<?php
set_time_limit(120);
require_once("../../inc/global.php");
require_once("../menusys/function.php");
if(!isset($_GET['type']) || !isset($_GET['id'])){
	adminislogin();
}
$globalurl = 'http://'.$_SERVER['HTTP_HOST'].'/'.ADMINROOT.'/System/htmlsys/createhtml.php';
if(isset($_GET['menuid'])){
	$where = 'menusys0='.$_GET['menuid'];
}else{
	$where = 'menusys0 > 3 ';
}
$menudata = $db->getlistarr('select * from menusys where '.$where);
$updatemenu = array();
$updateurl = array();
$PageNum = 0;
$updatamenuid = array();

foreach($menudata as $val){
	//if($val['menusys21']!=$val['menusys22']){
		
		$tempdata = array();
		$tempdata['menuid'] = $val['menusys0'];
		$tempdata['menutitle'] = $val['menusys1'];
		$tempdata['url'] = array();
		
		######################################
		####            内容页             ####
		######################################
		if((!empty($val['menusys16']) && !empty($val['menusys17'])) || (!empty($val['mmenusys16']) && !empty($val['mmenusys17']))){	
			$temptable = $val['menusys8'];
			$tempdatainfo = $db->getlistarr('select '.$temptable.'0 from '.$temptable.' where '.$temptable.'1='.$val['menusys0']);
			foreach($tempdatainfo as $listval){
				$tempdata['url'][] = '?type=detail&menuid='.$val['menusys0'].'&id='.$listval[$temptable.'0'];
				$PageNum++;
			}			
			
		}
		
		######################################
		####             列表页           ####
		######################################
		## PC端
		if(!empty($val['menusys14']) && !empty($val['menusys15'])){
			    $updatamenuid[] = $val['menusys0'];
				$htmlpagepath = $val['menusys14'];
				$htmlpagepath = base64_encode(gzcompress($htmlpagepath,9));
				$htmlpagepath = strtr($htmlpagepath,array('/'=>'_'));
				if($val['menusys18']>0){
					$d=$db->getlistarr("select classsys0,classsys1 from classsys where classsys4=".$val['menusys18']);
					foreach($d as $vals){
						$tempurl = $globalurl.'?type=list&menuid='.$val['menusys0'].'&rukou=pc&htmlpagepath='.$htmlpagepath.'&classid='.$vals['classsys0'].'&isstatusinfo=true';
						$status=get_headers($tempurl,1);
						if(strpos($status[0],'200')){
							if(isset($status['pagelength']) and $status['pagelength']>1){
								for($i=1;$i<=$status['pagelength'];$i++){
									$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=pc&htmlpagepath='.$htmlpagepath.'&classid='.$vals['classsys0'].'&page='.$i;
									$PageNum++;
								}
							}else{
								$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=pc&htmlpagepath='.$htmlpagepath.'&classid='.$vals['classsys0'];
								$PageNum++;
							}
						}
					}
				}else{
					$tempurl = $globalurl.'?type=list&menuid='.$val['menusys0'].'&rukou=pc&htmlpagepath='.$htmlpagepath.'&classid=&isstatusinfo=true';
					$status=get_headers($tempurl,1);
					
					if(strpos($status[0],'200')){
						if(isset($status['pagelength']) and $status['pagelength']>1){
							for($i=1;$i<=$status['pagelength'];$i++){
								$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=pc&htmlpagepath='.$htmlpagepath.'&classid=&page='.$i;
								$PageNum++;
							}
						}else{
							$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=pc&htmlpagepath='.$htmlpagepath.'&classid=';
							$PageNum++;
						}
					}
					
					
					
				}
		}
		
		## 移动端
		if(!empty($val['mmenusys14']) && !empty($val['mmenusys15'])){
				$updatamenuid[] = $val['menusys0'];
				$htmlpagepath = $val['mmenusys14'];
				$htmlpagepath = base64_encode(gzcompress($htmlpagepath,9));
				$htmlpagepath = strtr($htmlpagepath,array('/'=>'_'));
				if($val['menusys18']>0){
					$d=$db->getlistarr("select classsys0,classsys1 from classsys where classsys4=".$val['menusys18']);
					foreach($d as $vals){
						$tempurl = $globalurl.'?type=list&menuid='.$val['menusys0'].'&rukou=m&htmlpagepath='.$htmlpagepath.'&classid='.$vals['classsys0'].'&isstatusinfo=true';
						$status=get_headers($tempurl,1);
						if(strpos($status[0],'200')){
							if(isset($status['pagelength']) and $status['pagelength']>1){
								for($i=1;$i<=$status['pagelength'];$i++){
									$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=m&htmlpagepath='.$htmlpagepath.'&classid='.$vals['classsys0'].'&page='.$i;
									$PageNum++;
								}
							}else{
								$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=m&htmlpagepath='.$htmlpagepath.'&classid='.$vals['classsys0'];
								$PageNum++;
							}
						}
					}
				}else{
					
					$tempurl = $globalurl.'?type=list&menuid='.$val['menusys0'].'&rukou=m&htmlpagepath='.$htmlpagepath.'&classid=&isstatusinfo=true';
					$status=get_headers($tempurl,1);
					if(strpos($status[0],'200')){
						if(isset($status['pagelength']) and $status['pagelength']>1){
							for($i=1;$i<=$status['pagelength'];$i++){
								$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=m&htmlpagepath='.$htmlpagepath.'&classid=&page='.$i;
								$PageNum++;
							}
						}else{
							$tempdata['url'][] = '?type=list&menuid='.$val['menusys0'].'&rukou=m&htmlpagepath='.$htmlpagepath.'&classid=';
							$PageNum++;
						}
					}
					
					
					
				}
			
			
		}
		
		######################################
		####            单 页             ####
		######################################
		if((!empty($val['menusys13']) && !empty($val['menusys19'])) || (!empty($val['mmenusys13']) && !empty($val['mmenusys19']))){
			$tempdata['url'][] = '?type=onepage&menuid='.$val['menusys0'];
			$PageNum++;
		}
		
		
		
		
		
		
		
		if(count($tempdata['url'])>0){
			$updatemenu[] = $tempdata;
		}
	//}
}




/*
if(count($updatamenuid)<1){
	exit('没有需要更新的内容！');
}
//写的比较好
function a_array_unique($array){
   $out = array();
   foreach ($array as $key=>$value) {
       if (!in_array($value, $out)){
           $out[$key] = $value;
       }
   }
   return $out;
} 
$updatamenuid = a_array_unique($updatamenuid);
*/
//print_r($updatemenu);
/*
Array
(
    [0] => Array
        (
            [menuid] => 5
            [menutitle] => 新闻中心
            [url] => Array
                (
                    [0] => ?type=list&menuid=5&classid=18&page=1
                    [1] => ?type=list&menuid=5&classid=18&page=2
                    [2] => ?type=list&menuid=5&classid=18&page=3
                    [3] => ?type=list&menuid=5&classid=18&page=4
                    [4] => ?type=list&menuid=5&classid=18&page=5
                    [5] => ?type=list&menuid=5&classid=19
                    [6] => ?type=list&menuid=5&classid=20
                )
        )
)

*/
$urlarray = array();
foreach($updatemenu as $val){
	foreach($val['url'] as $urls){
		$urlarray[] = $globalurl.$urls;
		//$status=get_headers($globalurl.$urls,1);
	}
}
// echo '<pre>';
// print_r($urlarray);
// exit();
$html->includetop("","style=\"width:98%\";");
$starttime = microtime(true);
?>
<script charset="utf-8" src="./js/jquery.min.js"></script>
<script type="text/javascript">
//window.onbeforeunload = function() { 
//	return '正在更新静态请勿刷新或关闭页面！！';
//}
</script>
<br />
<div style="color:#F00; font-size:14px; line-height:16px;">温馨提示：正在更新静态请勿刷新或关闭页面！！</div><br />

<fieldset id="jingdutiao" style="border:#999 solid 1px; border-radius:4px;">
<legend style="font-size:14px;">更新进度</legend>
<div style="width:100%; height:10px; background:#fff; border:#06C solid 1px;border-radius:6px">
	<div id="jingdutiaoshow" style="width:0%; float:left; overflow:hidden; height:10px; background:#06C; border:0px;border-radius:4px"></div>
</div>
<div id="jingdushow">已更新：0%</div>
<div id="urliframe">更新状态：<iframe width="100%" height="30px" frameborder="0" id="createhtml" src="" scrolling="no"></iframe></div>
</fieldset>
<fieldset id="xiangxi" style="border:#999 solid 1px; border-radius:4px;">
<legend style="font-size:14px;">静态生成详细</legend>
<div id="recordlist" style="height:400px; width:100%; overflow:auto;"></div>
</fieldset>
<script type="text/javascript">
<?php
echo 'var dataurl = "'.implode('{urlsplit}',$urlarray).'";';
?>
var dataurlarray = dataurl.split('{urlsplit}');
var currentnum = 0;
var showcurrentnum = 1;
function rundataurl(returnval,returnval1){
	var width;
	if(returnval!=null){
		var t = returnval.split('{debugspsplit}');
		if(t[1]!=='false'){
			$('#recordlist').prepend(showcurrentnum+'. <a href="'+t[0]+'" target="_blank">'+t[0]+'</a>　<a href="'+t[1]+'" target="_blank">调试地址：'+t[1]+'</a><br />');
		}else{
			$('#recordlist').prepend(showcurrentnum+'. <a href="'+t[0]+'" target="_blank">'+t[0]+'</a><br />');
		}
		showcurrentnum++
	}
	if(returnval1!=null){
		var t1 = returnval.split('{debugspsplit}');
		if(t1[1]!=='false'){
			$('#recordlist').prepend(showcurrentnum+'. <a href="'+t1[0]+'" target="_blank">'+t1[0]+'</a>　<a href="'+t1[1]+'" target="_blank">调试地址：'+t1[1]+'</a><br />');
		}else{
			$('#recordlist').prepend(showcurrentnum+'. <a href="'+t1[0]+'" target="_blank">'+t1[0]+'</a><br />');
		}
		showcurrentnum++
	}
	if(currentnum < dataurlarray.length){
		$('#createhtml').attr('src',dataurlarray[currentnum]);
		width = (currentnum/(dataurlarray.length-1)*100)+'%';
		$('#jingdutiaoshow').css('width',width);
		$('#jingdushow').html('已更新：'+width);
		currentnum++;
	}else{
		width = '100%';
		$('#createhtml').attr('src','status.php?htmllen='+showcurrentnum+'&starttime=<?php echo $starttime ?>&upid=<?php echo implode(',',$updatamenuid);?>');
		$('#jingdutiaoshow').css('width',width);
		$('#jingdushow').html('已更新：'+width);
	}
}
rundataurl();
</script>
<?php
$html->includeend();
?>
